package com.zjdiepu.www.manage.api.dz;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.zjdiepu.www.base.BaseController;
import com.zjdiepu.www.base.annotation.Add;
import com.zjdiepu.www.base.annotation.Update;
import com.zjdiepu.www.base.core.AbstractSysUser;
import com.zjdiepu.www.base.core.ApiResponse;
import com.zjdiepu.www.base.core.PageVo;
import com.zjdiepu.www.base.enums.status.BusiStatus;
import com.zjdiepu.www.base.enums.status.DpStatus;
import com.zjdiepu.www.base.enums.type.OperateType;
import com.zjdiepu.www.base.enums.type.ResultFlagType;
import com.zjdiepu.www.base.enums.type.TypeData;
import com.zjdiepu.www.common.consts.ExcelTitleRowConsts;
import com.zjdiepu.www.common.util.CollectionInitUtil;
import com.zjdiepu.www.common.util.DateUtil;
import com.zjdiepu.www.common.util.ExcelUtil;
import com.zjdiepu.www.common.util.UUIDFactory;
import com.zjdiepu.www.common.util.ZhppDateUtil;
import com.zjdiepu.www.commpent.mapper.yw.YwBusinessVoMapper;
import com.zjdiepu.www.config.FileProperty;
import com.zjdiepu.www.ibiz.dz.IDzLoanMiddleBankImportBatchService;
import com.zjdiepu.www.ibiz.dz.IDzLoanMiddleBankService;
import com.zjdiepu.www.ibiz.yw.IYwBusinessService;
import com.zjdiepu.www.model.base.dto.SysUser;
import com.zjdiepu.www.model.dz.dto.DzLoanMiddleBank;
import com.zjdiepu.www.model.dz.dto.DzLoanMiddleBankImportBatch;
import com.zjdiepu.www.model.dz.ext.DzLoanMiddleBankExt;
import com.zjdiepu.www.model.yw.dto.YwBusiness;
import com.zjdiepu.www.model.yw.ext.YwBusinessExt;
import com.zjdiepu.www.model.yw.request.YwBusinessQueryRequest;
import com.zjdiepu.www.util.CommonUtil;
@RestController
@RequestMapping(value="DzLoanMiddleBankController", produces="application/json;charset=UTF-8")
@Api(tags = {"银行贷后登记"}, produces="application/json;charset=UTF-8")
public class DzLoanMiddleBankController extends BaseController{
//	private final Logger logger = LoggerFactory.getLogger(getClass());
	@Resource
	private IDzLoanMiddleBankService dzLoanMiddleBankService;
	@Resource
	private FileProperty fileProperty;
	@Resource
	private IYwBusinessService ywBusinessService;
	 @Resource
    private YwBusinessVoMapper ywBusinessVoMapper;
	 @Resource
	 private IDzLoanMiddleBankImportBatchService dzLoanMiddleBankImportBatchService;

    /**
     * @author zhangzhengjian <br/>
     * @Title: save  <br/>
     * @Description: 新增 <br/>
     * @param dzLoanMiddleBank
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "新增", response = Boolean.class, httpMethod="POST", tags={"新增"})
    @RequestMapping(value = "save", method = RequestMethod.POST)
    public ApiResponse save(@Validated(Add.class) @ModelAttribute DzLoanMiddleBank dzLoanMiddleBank) {
    	AbstractSysUser currentUser = getCurrentUser();
    	dzLoanMiddleBank.setModifier(currentUser.getId()); //统一使用修改人和修改人名称来初始化
    	dzLoanMiddleBank.setModifierName(currentUser.getName());
        dzLoanMiddleBankService.saveUpdateAndDelete(dzLoanMiddleBank, OperateType.add);
        return ApiResponse.success(true);
    }

    /**
     * @author zhangzhengjian <br/>
     * @Title: remove  <br/>
     * @Description: 删除<br/>
     * @param id
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "删除", response = Boolean.class, httpMethod="POST", tags={"删除"})
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "数据主键", paramType="query", required = true, example="1")
    })
    @RequestMapping(value = "remove", method = RequestMethod.POST)
    public ApiResponse remove(String id) {
    	if(StringUtils.isBlank(id)) {
    		return ApiResponse.fail(ResultFlagType.PARAM_EMPTY);
    	}
    	AbstractSysUser currentUser = getCurrentUser();
    	List<String> ids = Arrays.asList(id.split(","));
    	dzLoanMiddleBankService.updateBatch(currentUser.getId(), currentUser.getName(), DpStatus.DELETED.getCode(), ids);
        return ApiResponse.success(true);
    }
    
    /**
     * @author zhangzhengjian <br/>
     * @Title: disable  <br/>
     * @Description: 禁用<br/>
     * @param id
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "禁用", response = Boolean.class, httpMethod="POST", tags={"禁用"})
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "数据主键", paramType="query", required = true, example="1")
    })
    @RequestMapping(value = "disable", method = RequestMethod.POST)
    public ApiResponse disable(String id) {
    	if(StringUtils.isBlank(id)) {
    		return ApiResponse.fail(ResultFlagType.PARAM_EMPTY);
    	}
    	AbstractSysUser currentUser = getCurrentUser();
    	List<String> ids = Arrays.asList(id.split(","));
    	dzLoanMiddleBankService.updateBatch(currentUser.getId(), currentUser.getName(), DpStatus.INVALID.getCode(), ids);
        return ApiResponse.success(true);
    }
    
    /**
     * @author zhangzhengjian <br/>
     * @Title: enable <br/>
     * @Description: 启用<br/>
     * @param id
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "启用", response = Boolean.class, httpMethod="POST", tags={"启用"})
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "数据主键", paramType="query", required = true, example="1")
    })
    @RequestMapping(value = "enable", method = RequestMethod.POST)
    public ApiResponse enable(String id) {
    	if(StringUtils.isBlank(id)) {
    		return ApiResponse.fail(ResultFlagType.PARAM_EMPTY);
    	}
    	AbstractSysUser currentUser = getCurrentUser();
    	List<String> ids = Arrays.asList(id.split(","));
    	dzLoanMiddleBankService.updateBatch(currentUser.getId(), currentUser.getName(), DpStatus.NORMAL.getCode(), ids);
        return ApiResponse.success(true);
    }

    /**
     * @author zhangzhengjian <br/>
     * @Title: modify  <br/>
     * @Description: 修改 <br/>
     * @param dzLoanMiddleBank
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "修改", response = Boolean.class, httpMethod="POST", tags={"修改"})
    @RequestMapping(value = "modify", method = RequestMethod.POST)
    public ApiResponse modify(@Validated(Update.class) @ModelAttribute DzLoanMiddleBank dzLoanMiddleBank) {
    	AbstractSysUser currentUser = getCurrentUser();
    	dzLoanMiddleBank.setModifier(currentUser.getId()); //统一使用修改人和修改人名称来初始化
    	dzLoanMiddleBank.setModifierName(currentUser.getName());
    	dzLoanMiddleBankService.saveUpdateAndDelete(dzLoanMiddleBank, OperateType.edit);
        return ApiResponse.success(true);
    }

    /**
     * @author zhangzhengjian <br/>
     * @Title: getById  <br/>
     * @Description: 主键查询<br/>
     * @param id
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "主键查询", response = DzLoanMiddleBank.class, httpMethod="POST", tags={"主键查询"})
    @ApiImplicitParams({
        @ApiImplicitParam(name = "id", value = "数据主键", paramType="query", required = true, example="1")
    })
    @RequestMapping(value = "getById", method = RequestMethod.POST)
    public ApiResponse getById(String id){
    	if(StringUtils.isBlank(id)) {
    		return ApiResponse.fail(ResultFlagType.PARAM_EMPTY);
    	}
       DzLoanMiddleBank dzLoanMiddleBank = dzLoanMiddleBankService.selectById(id);
       if(null == dzLoanMiddleBank) {
    	   return ApiResponse.fail(ResultFlagType.MISSING);
       }
       return ApiResponse.success(dzLoanMiddleBank);
    }
    
    /**
     * @author zhangzhengjian <br/>
     * @Title: list  <br/>
     * @Description: 条件查询 <br/>
     * @param dzLoanMiddleBankExt
     * @return
     * @version V1.0  <br/>
     */
    @ApiOperation(value = "条件查询",response = DzLoanMiddleBank.class, httpMethod="POST", tags={"列表"})
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public ApiResponse list(@ModelAttribute DzLoanMiddleBankExt dzLoanMiddleBankExt){
        dzLoanMiddleBankExt.notDeleted();
        PageVo page = getPage(dzLoanMiddleBankExt);
        int records = dzLoanMiddleBankService.countByExt(dzLoanMiddleBankExt);
        page.setRecords(records);
        if (records > 0) {
            List<DzLoanMiddleBank> dpBaseDataDictionaries = dzLoanMiddleBankService.selectByExt(dzLoanMiddleBankExt);
            page.setRows(dpBaseDataDictionaries);
        } else {
            page.setRows(CollectionInitUtil.emptyList());
        }
        return ApiResponse.success(page);
    }
	/** 
	* @author zhangzj
	* @Title: importBankInfo 
	* @Description: 批量导入银行信息 
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ApiOperation(value = "批量导入银行信息",response = Boolean.class, httpMethod="POST", tags={"导入"})
    @RequestMapping(value="importBankInfo",method = RequestMethod.POST)
	public ApiResponse importBankInfo(String uploadName,String bankCode){
		AbstractSysUser currentUser = getCurrentUser();
		if(uploadName ==null || "".equals(uploadName)){
    		return ApiResponse.fail(ResultFlagType.PARAM_EMPTY);
    	}
		URL xmlpath = this.getClass().getClassLoader().getResource("");
		String pathTo="";
		String uuid=UUIDFactory.getUUID();
        try {
			pathTo=String.valueOf(xmlpath)+new String(fileProperty.getUploadPath().getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
        if(pathTo.contains("file:/")){
        	pathTo=pathTo.substring(6,pathTo.length());
        }
		String path=pathTo+uploadName;
		List<List<String>> list=ExcelUtil.getExcelContent(path,18);
		if(list==null || list.size()==0){
			return ApiResponse.fail(100300,"查询不到excel数据，请选择正确的excel数据导入！");
		}
		
		if(!list.get(0).containsAll(getTitleRow())|| !getTitleRow().containsAll(list.get(0))){
			return ApiResponse.fail(100300,"查询不到excel数据，请选择正确的excel数据导入！");
		};
		List<List<String>> listError=new ArrayList<List<String>>();
		if(list !=null && list.size()>0){
			List<DzLoanMiddleBank> listDhOverdue=new ArrayList<DzLoanMiddleBank>();
			DzLoanMiddleBank dzLoanMiddleBank=null;
			String code="";
			if(list.size()>1){
				for(int i=0;i<list.size();i++){
					for(int j=list.size()-1;j>i;j--){ 
						if(list.get(j).get(12).equals(list.get(i).get(12))){
							listError.add(list.get(j));
						}
					}
				}
			}
			YwBusinessExt ywBusinessExt= null;
			List<String> bankList=null;
			for(int i=1;i<list.size();i++){
				dzLoanMiddleBank= new DzLoanMiddleBank();
				bankList=list.get(i);
				code=bankList.get(12);
				if(code ==null || "".equals(code)){
					bankList.add("该客户在系统中查不到订单");
					listError.add(bankList);
					continue;
				}
				ywBusinessExt=new YwBusinessExt();
				ywBusinessExt.withOutPage();
				ywBusinessExt.notDeleted();
				ywBusinessExt.setCustomerNo(bankList.get(3));
				List<YwBusiness> list1=ywBusinessService.selectByExt(ywBusinessExt);
				if(list1==null || list1.isEmpty()){
					bankList.add("该客户在系统中查不到订单");
					listError.add(bankList);
					continue;
				}
				if(list1.size()>1){
					bankList.add("该客户有多笔订单，不支持导入");
					listError.add(bankList);
					continue;
				}
				String timeReceiveBank=bankList.get(1);
				if(timeReceiveBank.contains(".")){
					timeReceiveBank=timeReceiveBank.replace(".", "-");
				}
				String dateBank=bankList.get(8);
				if(dateBank.contains(".")){
					dateBank=dateBank.replace(".", "-");
				}
				String timeReceiveOpencard=bankList.get(11);
				if(timeReceiveOpencard.contains(".")){
					timeReceiveOpencard=timeReceiveOpencard.replace(".", "-");
				}
				String timeSubsequentInform=bankList.get(15);
				if(timeSubsequentInform.contains(".")){
					timeSubsequentInform=timeSubsequentInform.replace(".", "-");
				}
				String timeSubsequentReceive=bankList.get(16);
				if(timeSubsequentReceive.contains(".")){
					timeSubsequentReceive=timeSubsequentReceive.replace(".", "-");
				}
				dzLoanMiddleBank.setId(UUIDFactory.getUUID());
				dzLoanMiddleBank.setBusiId(list1.get(0).getId());
				dzLoanMiddleBank.setCusId(list1.get(0).getCustomerId());
//				dzLoanMiddleBank.setId(UUIDFactory.getUUID());
				dzLoanMiddleBank.setTimeReceiveBank2(bankList.get(0).equals("上午")?0:1);
				dzLoanMiddleBank.setTimeReceiveBank(DateUtil.convertStr2Date(timeReceiveBank));
				dzLoanMiddleBank.setDateBank(DateUtil.convertStr2Date(dateBank));
				dzLoanMiddleBank.setTxtPledge(bankList.get(10));
				dzLoanMiddleBank.setTimeReceiveOpencard(DateUtil.convertStr2Date(timeReceiveOpencard));
				dzLoanMiddleBank.setCardnoRefund(code);
				dzLoanMiddleBank.setContractNo(bankList.get(13));
				dzLoanMiddleBank.setRemarkSubsequent(bankList.get(14));
				dzLoanMiddleBank.setTimeSubsequentInform(DateUtil.convertStr2Date(timeSubsequentInform));
				dzLoanMiddleBank.setTimeSubsequentReceive(DateUtil.convertStr2Date(timeSubsequentReceive));
				dzLoanMiddleBank.setDpStatus(DpStatus.NORMAL.getCode());
				dzLoanMiddleBank.setTypeData(TypeData.SYSTEM.getCode());
				dzLoanMiddleBank.setCreator(currentUser.getId());
				dzLoanMiddleBank.setCreatorName(currentUser.getName());
				dzLoanMiddleBank.setCreated((int)(System.currentTimeMillis() / 1000));
				dzLoanMiddleBank.setModified((int)(System.currentTimeMillis() / 1000));
				dzLoanMiddleBank.setModifier(currentUser.getId());
				dzLoanMiddleBank.setModifierName(currentUser.getName());
				listDhOverdue.add(dzLoanMiddleBank);
			}
			Date d= new Date();
			String spath=CommonUtil.addressUploadFile+ZhppDateUtil.DateToString(d, "yyyyMMdd")+"//"+uploadName;
			if(listDhOverdue.size()>0){
				dzLoanMiddleBankService.batchInsert(listDhOverdue);
				
				//贷中银行批次表插入数据
				DzLoanMiddleBankImportBatch dzLoanMiddleBankImportBatch=new DzLoanMiddleBankImportBatch();
				dzLoanMiddleBankImportBatch.setId(uuid);
				dzLoanMiddleBankImportBatch.setDateReceipt(d);
				dzLoanMiddleBankImportBatch.setBank(bankCode);
				dzLoanMiddleBankImportBatch.setNumReceipt(listDhOverdue.size());
				dzLoanMiddleBankImportBatch.setFileName(uploadName);
				dzLoanMiddleBankImportBatch.setFileUrl(spath);
				dzLoanMiddleBankImportBatchService.saveUpdateAndDelete(dzLoanMiddleBankImportBatch, OperateType.add);
				
			}
			if(listError!=null && listError.size()>0){
				File file = new File(CommonUtil.addressUploadFile+ZhppDateUtil.DateToString(d, "yyyyMMdd"));
				if(!file.exists()){
					file.mkdirs();
				}
				ExcelUtil.importExcel(spath, ExcelTitleRowConsts.EXCELTYPE1, listError, getTitleRow());
//				return ApiResponse.fail(111111,"部分客户导入未成功，具体原因请查询 "+pathTo+"银行错误信息.xlsx");
			}
		}
		return ApiResponse.success(true);
	}
	/** 
	* @author zhangzj
	* @Title: previewDueList 
	* @Description: 预览excel列表
	* @param @param uploadName
	* @param @return    设定文件 
	* @return ApiResponse    返回类型 
	* @version V1.0
	* @throws 
	*/
	@ApiOperation(value = "预览excel列表",response = PageVo.class, httpMethod="POST", tags={"列表"})
    @RequestMapping(value="previewDueList",method = RequestMethod.POST)
	public ApiResponse previewDueList(String uploadName,boolean initFlag){
		if(initFlag==true){
			return ApiResponse.success(CollectionInitUtil.emptyList());
		}
		if(uploadName ==null || "".equals(uploadName)){
			return ApiResponse.fail(ResultFlagType.PARAM_EMPTY);
		}
		URL xmlpath = this.getClass().getClassLoader().getResource("");
		String pathTo="";
        try {
			pathTo=String.valueOf(xmlpath)+new String(fileProperty.getUploadPath().getBytes("ISO-8859-1"),"UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
        if(pathTo.contains("file:/")){
        	pathTo=pathTo.substring(6,pathTo.length());
        }
		List<List<String>> list=ExcelUtil.getExcelContent(pathTo+uploadName,18);
		
		if(list==null || list.size()==0){
			return ApiResponse.fail(100300,"查询不到excel数据，请选择正确的excel数据导入！");
		}
		
		if(!list.get(0).containsAll(getTitleRow())|| !getTitleRow().containsAll(list.get(0))){
			return ApiResponse.fail(100300,"查询不到excel数据，请选择正确的excel数据导入！");
		};
		List<DzLoanMiddleBank> listDhOverdue=new ArrayList<DzLoanMiddleBank>();
		DzLoanMiddleBank dzLoanMiddleBank= new DzLoanMiddleBank();
		for(int i=1;i<list.size();i++){
			List<String> bankList=list.get(i);
			dzLoanMiddleBank= new DzLoanMiddleBank();
			dzLoanMiddleBank.setCreatorName(bankList.get(2));
			dzLoanMiddleBank.setCusNo(bankList.get(3));
			dzLoanMiddleBank.setLoanAmount(bankList.get(6)==null?0:Double.parseDouble((String)bankList.get(6)));
			dzLoanMiddleBank.setLoanDate(DateUtil.convertStr2Date(bankList.get(8)==null?null:bankList.get(8).replace(".", "-")));
			dzLoanMiddleBank.setLoanStatus(bankList.get(9));
			dzLoanMiddleBank.setTxtPledge(bankList.get(10)==null?"":bankList.get(10));
			dzLoanMiddleBank.setCardnoRefund(bankList.get(12));
			dzLoanMiddleBank.setContractNo(bankList.get(13)==null?"":bankList.get(13));
//			dzLoanMiddleBank.setTimeReceiveBank2(bankList.get(0).equals("上午")?0:1);
//			dzLoanMiddleBank.setTimeReceiveBank(DateUtil.convertStr2Date(bankList.get(1).replace(".", "-")));
//			dzLoanMiddleBank.setDateBank(DateUtil.convertStr2Date(bankList.get(8).replace(".", "-")));
//			dzLoanMiddleBank.setTimeReceiveOpencard(DateUtil.convertStr2Date(bankList.get(11).replace(".", "-")));
//			dzLoanMiddleBank.setRemarkSubsequent(bankList.get(14)==""?null:bankList.get(14));
//			dzLoanMiddleBank.setTimeSubsequentInform(DateUtil.convertStr2Date(bankList.get(15)==null?null:bankList.get(15).replace(".", "-")));
//			dzLoanMiddleBank.setTimeSubsequentReceive(DateUtil.convertStr2Date(bankList.get(16)==null?null:bankList.get(16).replace(".", "-")));
			listDhOverdue.add(dzLoanMiddleBank);
			if(i>=50) break;
		}
		PageVo page = new PageVo();
		page.setRecords(1);
		page.setRows(listDhOverdue);
		return ApiResponse.success(page);
	}
		/** 
		* @author zhangzj
		* @Title: getTitleRow 
		* @Description: 生成错误数据的表头 
		* @param @return    设定文件 
		* @return List<String>    返回类型 
		* @version V1.0
		* @throws 
		*/
		private List<String> getTitleRow() {
			List<String> arr1= new ArrayList<String>();
			arr1.add(ExcelTitleRowConsts.EXCELROW30);
			arr1.add(ExcelTitleRowConsts.EXCELROW31);
			arr1.add(ExcelTitleRowConsts.EXCELROW32);
			arr1.add(ExcelTitleRowConsts.EXCELROW33);
			arr1.add(ExcelTitleRowConsts.EXCELROW34);
			arr1.add(ExcelTitleRowConsts.EXCELROW35);
			arr1.add(ExcelTitleRowConsts.EXCELROW36);
			arr1.add(ExcelTitleRowConsts.EXCELROW37);
			arr1.add(ExcelTitleRowConsts.EXCELROW38);
			arr1.add(ExcelTitleRowConsts.EXCELROW39);
			arr1.add(ExcelTitleRowConsts.EXCELROW40);
			arr1.add(ExcelTitleRowConsts.EXCELROW41);
			arr1.add(ExcelTitleRowConsts.EXCELROW42);
			arr1.add(ExcelTitleRowConsts.EXCELROW43);
			arr1.add(ExcelTitleRowConsts.EXCELROW44);
			arr1.add(ExcelTitleRowConsts.EXCELROW45);
			arr1.add(ExcelTitleRowConsts.EXCELROW46);
			arr1.add(ExcelTitleRowConsts.EXCELROW47);
//			arr1.add(ExcelTitleRowConsts.EXCELROW48);
			return arr1;
	}
		/**
	     * @author xiongxiaotun <br/>
	     * @Title: list  <br/>
	     * @Description: 条件查询业务信息 <br/>
	     * @param ywBusinessExt
	     * @return
	     * @version V1.0  <br/>
	     */
	    @ApiOperation(value = "条件查询业务信息",response = YwBusiness.class, httpMethod="POST", tags={"多表查询"})
	    @RequestMapping(value = "multiList", method = RequestMethod.POST)
	    public ApiResponse multiList(@Validated @ModelAttribute YwBusinessQueryRequest ywBusinessQueryRequest){
	    	SysUser sysUser = (SysUser)getCurrentUser();
	        PageVo page = getPage(ywBusinessQueryRequest);
	        ywBusinessQueryRequest.setBaseWhere();
	        ywBusinessQueryRequest.setBankLoan(sysUser.getLoanBank());
	        ywBusinessQueryRequest.setBusiStatusMore(BusiStatus.YIN_HANG_YI_FANG_KUAN.getCode());
	        ywBusinessQueryRequest.setBusiStatusLess(BusiStatus.CHU_SHEN_DAN_CHU_SHEN_ZHONG.getCode());
	        ywBusinessQueryRequest.setTimeApplyOpencardFlag(true);
//	        ywBusinessQueryRequest.setTimeContractFullFlag(false);
	        int records = ywBusinessService.countMultiByExt(ywBusinessQueryRequest);
	        page.setRecords(records);
	        if (records > 0) {
	        	DzLoanMiddleBank dzLoanMiddleBank=null;
	            List<YwBusiness> ywBusinesss = ywBusinessService.selectMultiByExt(ywBusinessQueryRequest);
	            for (YwBusiness ywBusiness : ywBusinesss) {
	            	dzLoanMiddleBank=new DzLoanMiddleBank();
	            	dzLoanMiddleBank.setBusiId(ywBusiness.getId());
	            	dzLoanMiddleBank=dzLoanMiddleBankService.selectRefined(dzLoanMiddleBank);
	            	if(dzLoanMiddleBank!=null){
	            		ywBusiness.setMiddleBankId(dzLoanMiddleBank.getId());
	            		ywBusiness.setBankStatusDisplay("已保存");
	            	}
				}
	            ywBusinessVoMapper.mapper(ywBusinesss);
	            page.setRows(ywBusinesss);
	        } else {
	            page.setRows(CollectionInitUtil.emptyList());
	        }
	        return ApiResponse.success(page);
	    }
}
